导航菜单
首页 >  ACM真题 字符串匹配  > 【华为OD】机试真题

【华为OD】机试真题

题目描述输入两个字符串S和L,都只包含英文小写字母。S长度 s >> l; // 从标准输入读取两个字符串到s和lint last_idx = -1; // 初始化last_idx为-1,表示找不到时的返回值int m = s.length(); // 计算字符串s的长度int n = l.length(); // 计算字符串l的长度int to_match = 0;// 初始化匹配的位置为0// 遍历字符串lfor (int i = 0; i < n; i++) {if (s[to_match] == l[i])to_match++, last_idx = i; // 增加匹配位置,更新最后匹配的索引if (to_match >= m) break; // 如果全部字符都已匹配,则退出循环}cout

相关推荐: